/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import beans.Admin;
import beans.DBMS;
import beans.SubAdmin;
import beans.item;
import java.sql.ResultSet;
import javassist.bytecode.stackmap.BasicBlock;

/**
 *
 * @author appi
 */
public class AdminDao {

    private static DBMS d = new DBMS();
    private static int iid;
    public static boolean verify(Admin a) {
        boolean flag = false;
        String sql = "select * from admin where ademail='" + a.getADemail() + "' AND adpassword='" + a.getADpassword() + "'";
        ResultSet rs = d.gselect(sql);
        try {
            while (rs.next()) {
                flag = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
    
 public static boolean subVerify(SubAdmin sa) {
        boolean flag = false;
        String sql = "select * from subadmin where email='" + sa.getEmail() + "' AND password='" + sa.getPassword() + "'";
        ResultSet rs = d.gselect(sql);
        try {
            while (rs.next()) {
                flag = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
 }
    public static boolean filluser(SubAdmin sa) {
        boolean flag = false;

        String sql = "insert into subadmin(fname,lname,email,password) values('" + sa.getFname() + "','" + sa.getLname() + "','" + sa.getEmail() + "','" + sa.getPassword() + "')";
        if (d.guid(sql) == 1) {
            flag = true;
        }
        return flag;

    }

    public static int additem(item iad) {
        
        String sql="insert into `items` (`iname`, `iprice`, `istock`, `isdesc`, `iddesc`) values('"+iad.getIname()+"','"+iad.getIprice()+"','"+iad.getIstock()+"','"+iad.getIsdesc()+"','"+iad.getIddesc()+ "')";
         try {
            if (d.guid(sql) == 1) {

                ResultSet rs = null;
                String sql1 = "select MAX(`iid`) AS `I` from `items`";
                rs = d.gselect(sql1);
                while(rs.next()){
                    iid= rs.getInt("I");
                }
               
            }
         }
             catch(Exception e)
                     {
                       e.printStackTrace();
                     }
         return iid;
    }
}
